import React, { Component } from 'react'

interface IState {
  count: string
}
//<props,state> 第一个参数是对参数做限制，第二个表示对状态做限制
export default class Demo extends Component<any, IState> {
  state = {
    count: '123'
  }
  changeCount=()=>{
    //代码未执行是this.myRef.current.value可能是空所以加上as断言表示断定其有值
    console.log((this.myRef.current as HTMLInputElement).value);
    this.setState({count:(this.myRef.current as HTMLInputElement).value})
  }
  myRef=React.createRef<HTMLInputElement>()
  render() {
    return (
      <div>
        <input type="text" ref={this.myRef} />
        {this.state.count}
        <button onClick={this.changeCount}>修改num</button>
        <Child name={'lzzzzz'}/>
      </div>
    )
  }
}
interface IProps {
  name: string
}
class Child extends Component<IProps,any>{
  render(){
    console.log(this.props.name);
    return (
      <h1>{this.props.name}</h1>
    )
  }
  
  
}
